#include <bits/stdc++.h>
// 2025/01/24
// tag: 
// Author: Zhang Muen
using namespace std;

int q, op, x;

signed main()
{
    set<int> s;
    s.insert(INT_MAX);
    cin >> q;
    while (q--){
        cin >> op >> x;
        if (op == 1){
            auto p = s.lower_bound(x);
            int cnt = distance(s.begin(), p); 
            cout << cnt + 1 << endl; 
        }
        else if (op == 2){
            auto p = s.begin();
            advance(p, x - 1); 
            cout << *p << endl;
        }
        else if (op == 3){
            auto p = s.lower_bound(x);
            if (p == s.begin())
                cout << -2147483647 << endl;
            else
                cout << *(--p) << endl;
        }
        else if (op == 4){
            auto p = s.upper_bound(x);
            cout << *p << endl; 
        }
        else {
            s.insert(x);
        }
    }
    return 0;
}